﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 飞行（带有磁铁效果）
public class BuffFly : BuffMagnet
{
    const float speedUpMul = 2; // 加速倍率
    const float minSpeed = 8; // 最小飞行速度
    GameObject _effect;

    // 飞行过程中，撞毁所有阻挡和怪物
    DestroyWhenFly _destroyObj;

    protected override void onStart()
    {
        base.onStart();
        var flySpeed = Mathf.Max(minSpeed, _owner.BaseMoveSpeed * speedUpMul);
        //Debug.Log("flySpeed = " + flySpeed);
        _owner.SetFlyState(true, flySpeed);

        _effect = addEffect("Effect/Fly");
        _destroyObj = new DestroyWhenFly();
        _destroyObj.Init(_owner.transform, (obj) => GameObject.Destroy(obj),
            (enemy) => enemy.BeAttacked(_owner));
    }

    protected override void onFinish()
    {
        base.onFinish();
        _owner.SetFlyState(false);

        GameObject.Destroy(_effect);
        _destroyObj.Release();
    }
}
